 import axios from  'axios';
import {fromJS} from 'immutable';
import * as constants from './constants';
//定义方法
export  const togoTop=(show)=>({
    type:constants.TOGGLE_SCROLL_TOP,
    show
});
 const  changeImg=(data)=>({
     type:constants.CHANGE_IMG,
     images:fromJS(data)  //吧数据转为immutable类型
 });
 const  changeHome=(data)=>({
     type:constants.CHANGE_HOME,
     News:fromJS(data.news),
     Teacher:fromJS(data.teacher),
     Student:fromJS(data.student),
     baseBar:fromJS(data.bar)
 });
export  const goto=()=>{
    return (dispatch) => {

        axios.get(window.ip+'/getViewpager').then((res)=>{
            dispatch(changeImg(res.data));
        }).catch(()=>{
            console.log('err-404');
        });

        axios.get(window.ip+'/getHome').then((res)=>{
            dispatch(changeHome(res.data));
        }).catch(()=>{
            console.log('err-404');
        });

    }
}